package com.zyl.blog.common.strategy;

import com.zyl.blog.common.annotation.Sensitive;

/**
 * 手机号脱敏策略
 * 保留前3位和后4位，中间4位用*代替
 * 示例：138****5678
 * @version v1.0
 * @ProjectName: Personal_Blog_Server
 * @Package: com.zyl.blog.common.strategy
 * @ClassName: PhoneSensitiveStrategy
 * @Author FinalFantasy
 * @Date 2025/9/8-10:31
 */
public class PhoneSensitiveStrategy extends AbstractSensitiveStrategy {

    @Override
    public String desensitize(String value, Sensitive annotation) {
        // 如果注解指定了前缀或后缀长度，则使用注解配置
        if (annotation.prefixLen() > 0 || annotation.suffixLen() > 0) {
            return super.desensitize(value, annotation);
        }

        // 默认手机号脱敏规则：前3后4
        return mask(value, 3, 4, annotation.maskChar());
    }
}
